﻿using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.OleDb;
using System.Linq;
using System.Net;
using System.Net.Sockets;
using System.Runtime.CompilerServices;
using System.Windows;
using System.Windows.Media;

namespace CosAging
{
    public class Parameter : INotifyPropertyChanged

    {
        int Row1;
        public int Row
        {
            get
            {
                return Row1;
            }
            set
            {
                Row1 = value;
                NotifyPropertyChanged("Row");
            }
        }

        int Column1;
        public int Column
        {
            get
            {
                return Column1;
            }
            set
            {
                Column1 = value;
                NotifyPropertyChanged("Column");
            }
        }

        string Content1;
        public string Content
        {
            get
            {
                return Content1;
            }
            set
            {
                Content1 = value;
                NotifyPropertyChanged("Content");
            }
        }

        SolidColorBrush Add_Background1;
        public SolidColorBrush Add_Background
        {
            get
            {
                return Add_Background1;
            }
            set
            {
                Add_Background1 = value;
                NotifyPropertyChanged("Add_Background");
            }
        }

        public event PropertyChangedEventHandler PropertyChanged;
        private void NotifyPropertyChanged([CallerMemberName] String propertyName = "")
        {
            if (PropertyChanged != null)
            {
                PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
            }
        }
    }

    
    public class Equipment
    {
        public int Local_ID { get; set; }
        public string Local_EquipmentName { get; set; }
        public ConcurrentDictionary<int, Parameter> Local_Parameter { get; set; }
    }


    class AccessDB
    {
        public static string Apppath = AppDomain.CurrentDomain.SetupInformation.ApplicationBase; //获取启动了应用程序的可执行文件的路径，不包括可执行文件的名称


        public static ConcurrentDictionary<int, Equipment> DicEquipment = new ConcurrentDictionary<int, Equipment>();


        //==========================================================================================================================
        private static string DatabasePath1 = "X:\\CC\\CNCC-WQ\\Blue Group\\Blue Group\\CC-CCS\\Production\\maintenance\\Common document\\Shell\\保养系统文件\\DataBase.mdb"; 
  
        private static OleDbConnection myConnection1 = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source= " + DatabasePath1 + " ;"); //.mdb
        private static string SqlStr1 = "select * from EquipmentContent order by ID ASC";
        private static OleDbDataAdapter MyDataAdapter1 = new OleDbDataAdapter(SqlStr1, myConnection1);
        private static OleDbCommandBuilder myCommandBuilder1 = new OleDbCommandBuilder(MyDataAdapter1);

        public static DataTable myDataTable1 = new DataTable();

        public static DataRow[] myDataRow1;
        //==========================================================================================================================

        public static void Access_Initialize()
        {
            try
            {
            
                myCommandBuilder1.QuotePrefix = "[";
                myCommandBuilder1.QuoteSuffix = "]";
                myConnection1.Open();
                MyDataAdapter1.Fill(myDataTable1);
                myDataRow1 = myDataTable1.Select();


                for (int i = 0; i < myDataRow1.Count(); i++)
                {
                    ConcurrentDictionary<int, Parameter> Parameter = new ConcurrentDictionary<int, Parameter>();
                    for (int j = 0; j < 12; j++)
                    {
                        if (i < 23)
                        {
                            Parameter DataRow1 = new Parameter()
                            {
                                Row = i + 2,
                                Column = j + 1,
                                Content = Convert.ToString(myDataRow1[i][j + 2]).Trim(),
                                Add_Background = null
                            };

                            Parameter.TryAdd(j, DataRow1);
                        }
                        else
                        {
                            Parameter DataRow1 = new Parameter()
                            {
                                Row = i + 2 - 23,
                                Column = j + 1 + 13,
                                Content = Convert.ToString(myDataRow1[i][j + 2]).Trim(),
                                Add_Background = null
                            };

                            Parameter.TryAdd(j, DataRow1);
                        }
                    }

                    Equipment DataRow = new Equipment()
                    {
                        Local_ID = Convert.ToInt32(myDataRow1[i]["ID"]),
                        Local_EquipmentName = Convert.ToString(myDataRow1[i]["EquipmentName"]),
                        Local_Parameter = Parameter
                    };

                    DicEquipment.TryAdd(i, DataRow);
                }

            }

            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }

        }



    }
}
